<?php

use Faker\Factory as Faker;
use App\Models\Layout;
use App\Repositories\LayoutRepository;

trait MakeLayoutTrait
{
    /**
     * Create fake instance of Layout and save it in database
     *
     * @param array $layoutFields
     * @return Layout
     */
    public function makeLayout($layoutFields = [])
    {
        /** @var LayoutRepository $layoutRepo */
        $layoutRepo = App::make(LayoutRepository::class);
        $theme = $this->fakeLayoutData($layoutFields);
        return $layoutRepo->create($theme);
    }

    /**
     * Get fake instance of Layout
     *
     * @param array $layoutFields
     * @return Layout
     */
    public function fakeLayout($layoutFields = [])
    {
        return new Layout($this->fakeLayoutData($layoutFields));
    }

    /**
     * Get fake data of Layout
     *
     * @param array $postFields
     * @return array
     */
    public function fakeLayoutData($layoutFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'image_type' => $fake->randomDigitNotNull,
            'skip_type' => $fake->randomDigitNotNull,
            'image_name' => $fake->word,
            'image2_name' => $fake->word,
            'skip_id' => $fake->randomDigitNotNull,
            'skip_url' => $fake->text,
            'skip2_id' => $fake->randomDigitNotNull,
            'skip2_url' => $fake->text,
            'image' => $fake->text,
            'image2' => $fake->text,
            'sort' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $layoutFields);
    }
}
